<?php

require_once(ABSPATH . 'portal/main.php');

class Portal extends Main {
	
	function Portal() {
		parent::Main();
		$this->database();	
		$this->lib('pagination');
	}
	
	function index() {
		$article_list = $this->db->find('select * from article order by created desc limit 0, 20');
		
		$total = $this->db->count('project');
		$config = array(
			'total_row' => $total,
			'page_size' => 8
		);
		$this->pagination->init( $config );
		$work_list = $this->db->find('select * from project order by created desc limit ' . $this->pagination->start_row . ',' . $this->pagination->page_size);
		
		$new_work_list = array();
		foreach( $work_list as $work ) {
			$work['service_list'] = $this->db->find(
				'select s.name, s.url_name from service s, service_project sp where s.id=sp.service_id and sp.project_id=' . $work['id']);
			array_push($new_work_list, $work);
		}
		
		$data = array(
			'article_list'=>$article_list,
			'work_list' => $new_work_list
		);
		$this->my_view('portal/index', $data);
	}
	
}

?>